package com.it.schoolbookshop_back.entities.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Base64;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class BookResponseDTO {
    private Integer id;
    private String title;
    private String author;
    
    @JsonProperty("category_id")
    private Integer categoryId;
    
    private String category;
    
    private BigDecimal price;
    
    @JsonProperty("book_condition")
    private String bookCondition;
    
    @JsonProperty("new_degree")
    private Integer newDegree;
    
    private String description;
    
    private String cover; // 存储图片路径或Base64编码的图片数据
    
    @JsonProperty("cover_type")
    private String coverType;
    
    @JsonProperty("seller_id")
    private Integer sellerId;
    
    @JsonProperty("seller_name")
    private String sellerName;
    
    private String department;
    
    private String status;
    private Integer views;
    
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonProperty("created_at")
    private LocalDateTime createdAt;
    
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonProperty("updated_at")
    private LocalDateTime updatedAt;
    
    // 工具方法：将byte[]转换为Base64字符串
    public static String byteArrayToBase64(byte[] bytes) {
        if (bytes == null || bytes.length == 0) {
            return null;
        }
        return Base64.getEncoder().encodeToString(bytes);
    }
} 